<html>
<head><meta charset="utf-8"><title>add dependency when feature disabled · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html">add dependency when feature disabled</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="150924243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924243">(Dec 05 2018 at 12:32)</a>:</h4>
<p>Is there a way to make an optional dependency non-optional if a cargo feature is disabled ?</p>



<a name="150924623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924623">(Dec 05 2018 at 12:41)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> cargo features are expected to be additive, not negative</p>



<a name="150924626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924626">(Dec 05 2018 at 12:41)</a>:</h4>
<p>a lot of stuff breaks if they are negative</p>



<a name="150924714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924714">(Dec 05 2018 at 12:43)</a>:</h4>
<p>so that's the problem, say a crate wants to support <code>no_std</code>, and it adds a <code>use_std</code> feature enabled by default</p>



<a name="150924737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924737">(Dec 05 2018 at 12:43)</a>:</h4>
<p>when it is disabled, the crate should be <code>no_std</code>, but for that it would like to use a <code>no_std</code> dependency that is not needed when <code>std</code> is available</p>



<a name="150924793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924793">(Dec 05 2018 at 12:44)</a>:</h4>
<p>that is, "if <code>use_std</code> is not enabled, then add a dependency"</p>



<a name="150924805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924805">(Dec 05 2018 at 12:45)</a>:</h4>
<p>if we need an additive feature to add the <code>no_std</code> dependency, we might just call that feature <code>no_std</code>, and we have added a negative feature</p>



<a name="150924930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924930">(Dec 05 2018 at 12:47)</a>:</h4>
<p>teechnically you can do <code>[dependencies.'anycfghere'.foo]</code> IIRC</p>



<a name="150924985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150924985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150924985">(Dec 05 2018 at 12:48)</a>:</h4>
<p><a href="https://github.com/nagisa/rust_libloading/blob/master/Cargo.toml#L15" target="_blank" title="https://github.com/nagisa/rust_libloading/blob/master/Cargo.toml#L15"><code>[target.'cfg(not(use_std))'.dependencies.dep]</code></a> for example...</p>



<a name="150925020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150925020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150925020">(Dec 05 2018 at 12:49)</a>:</h4>
<p>third try’s the charm ^)</p>



<a name="150925113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150925113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150925113">(Dec 05 2018 at 12:51)</a>:</h4>
<p><code>[target.</code>cfg(not(feature = "use_std"))<code>.dependencies.dep]</code> should work indeed</p>



<a name="150925179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150925179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150925179">(Dec 05 2018 at 12:53)</a>:</h4>
<p>Somehow I have a sinking feeling that I’ve recommended a similar thing before but it turned out that cargo has a white/blacklist of supported cfgs and only allows very limited subset of cfgs :D</p>



<a name="150925675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150925675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150925675">(Dec 05 2018 at 13:01)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> <a href="https://github.com/rust-lang/cargo/issues/1839" target="_blank" title="https://github.com/rust-lang/cargo/issues/1839">https://github.com/rust-lang/cargo/issues/1839</a></p>



<a name="150925679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/add%20dependency%20when%20feature%20disabled/near/150925679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/add.20dependency.20when.20feature.20disabled.html#150925679">(Dec 05 2018 at 13:01)</a>:</h4>
<p>yep, that doesn't work</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>